<?php
/**
 * 
 * @author Freezy
 */
class SearchDialog extends MY_Controller {

	function SearchDialog(){
		parent::MY_Controller();
		$this->validate_cookie();
	}
	
	/********************************
	 * karyawan search dialog
	 ********************************/
	function karyawan($func){
		$this->{"_karyawan_$func"}();
	}
	
	function _karyawan_getDialog(){
		$this->load->config('rnd',true);
		$conf = $this->config->item('rnd');
		$this->load->model('karyawan_model');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		$where = $this->input->post('where');
		
		$this->load->view('utils/searchDialog/karyawan/searchDialog', array(
			'return_fields'=>$return_fields? $return_fields : "kary_id,kary_nama",
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'where'=>$where,
			'limit'=>$conf['search']['limit'],
		
			'kary_data' => $this->karyawan_model->select_last_entry("",$where)
		));
	}
	
	/**
	 * 
	 * @param $callback (function) - function callback with ('kary_id', 'kary_nama') param/argument
	 */
	function _karyawan_search(){
		$this->load->model('karyawan_model');

		$key = $this->input->post('key');
		$limit = $this->input->post('limit');
		$offset = $this->input->post('offset') * $limit;
		$orderby = $this->input->post('orderby');
		$where = $this->input->post('where');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		
		$table_content = "";
		$row = 0;
		$data = array(
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'return_fields'=>$return_fields,
		
			'kary_data'=>$this->karyawan_model->select_last_entry($key, $where, $limit, $offset, $orderby),
		);
		$table_content = $this->load->view('utils/searchDialog/karyawan/searchDialog_tableContent', $data,true); 	
		echo json_encode(array(
			'table_content'=> $table_content,
			'table_num_record'=> $key? $data['kary_data']->num_rows() : $this->karyawan_model->count_record()
		));
	}
	
	/* end of karyawan search dialog *************************************************************/
	
	
	/********************************
	 * jabatan search dialog
	 ********************************/
	function jabatan($func, $a=false, $b=false, $c=false, $d=false){
		$this->{"_jabatan_$func"}($a, $b, $c, $d);
	}
	
	function _jabatan_getDialog(){
		$this->load->model('jabatan_model');
		$this->load->config('rnd',true);
		$conf = $this->config->item('rnd');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		$where = $this->input->post('where');
		
		$this->load->view('utils/searchDialog/jabatan/searchDialog', array(
			'return_fields'=>$return_fields? $return_fields : "jbt_id,jbt_nama",
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'where'=>$where,
			'limit'=>$conf['search']['limit'],
		
			'data'=>$this->jabatan_model->select_last_entry("",$where)
		));
	}
	
	/**
	 * 
	 * @param $callback (function) - function callback with ('kary_id', 'kary_nama') param/argument
	 */
	function _jabatan_search(){
		$this->load->model('jabatan_model');

		$key = $this->input->post('key');
		$limit = $this->input->post('limit');
		$offset = $this->input->post('offset') * $limit;
		$orderby = $this->input->post('orderby');
		$where = $this->input->post('where');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		
		$table_content = "";
		$row = 0;
		$data = array(
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'return_fields'=>$return_fields,
		
			'data'=>$this->jabatan_model->select_last_entry($key, $where, $limit, $offset, $orderby),
		);
		$table_content = $this->load->view('utils/searchDialog/jabatan/searchDialog_tableContent', $data,true);
		echo json_encode(array(
			'table_content'=> $table_content,
			'table_num_record'=> $key? $data['data']->num_rows() : $this->jabatan_model->count_record()
		));
	}
	
	/* end of jabatan search dialog *************************************************************/	
	
	/********************************
	 * detachievement search dialog
	 ********************************/
	function detachievement($func){
		$this->{"_detachievement_$func"}();
	}
	
	function _detachievement_getDialog(){
		$this->load->model('detachievement_model');
		$this->load->config('rnd',true);
		$conf = $this->config->item('rnd');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		$where = $this->input->post('where');
		$translate = $this->input->post('translate');
		
		$this->load->view('utils/searchDialog/detachievement/searchDialog', array(
			'return_fields'=>$return_fields? $return_fields : "detachiev_id",
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'where'=>$where,
			'limit'=>$conf['search']['limit'],
			
			'translate'=>$translate,
			'jenis_options'=>$conf['achievement']['jenis_options'],
			'tingkat_options'=>array_merge(
				$conf['detachievement']['tingkat_options']['PR'], 
				$conf['detachievement']['tingkat_options']['PE']),
			'data'=>$this->detachievement_model->select_last_entry("",$where)
		));
	}
	
	/**
	 * 
	 * @param $callback (function) - function callback with ('kary_id', 'kary_nama') param/argument
	 */
	function _detachievement_search(){
		$this->load->model('detachievement_model');
		$this->load->config('rnd',true);
		$conf = $this->config->item('rnd');
		$conf1 = $conf['achievement']['jenis_options'];
		$conf2 = array_merge(
			$conf['detachievement']['tingkat_options']['PR'],
			$conf['detachievement']['tingkat_options']['PE']);
		
		//ada kodenya, jadi load config dulu
		$key = $this->input->post('key');
		$keysss = array();
		$keysss[] = $key; 
		if ($ss = array_search(ucwords($key), $conf1)) $keysss[] = $ss;	//key untuk jenis
		if ($ss = array_search(ucwords($key), $conf2)) $keysss[] = $ss;	//key untuk tingkat
		
		$limit = $this->input->post('limit');
		$offset = $this->input->post('offset') * $limit;
		$orderby = $this->input->post('orderby');
		$where = $this->input->post('where');
		$translate = $this->input->post('translate');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		
		$table_content = "";
		$row = 0;
		$data = array(
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'return_fields'=>$return_fields? $return_fields : "detachiev_id",
			
			'translate'=>$translate? $translate : false,
			'jenis_options'=>$conf1,
			'tingkat_options'=>$conf2,
			'data'=>$this->detachievement_model->select_last_entry($keysss, $where, $limit, $offset, $orderby),
		);
		$table_content = $this->load->view('utils/searchDialog/detachievement/searchDialog_tableContent', $data,true);
		echo json_encode(array(
			'table_content'=> $table_content,
			'table_num_record'=> $key? $data['data']->num_rows() : $this->detachievement_model->count_record()
		));
	}
	
	/* end of detachievement search dialog *************************************************************/

	/********************************
	 * rewardPunishment search dialog
	 ********************************/
	function rewardPunishment($func, $a=false, $b=false, $c=false, $d=false){
		$this->{"_rewardPunishment_$func"}($a, $b, $c, $d);
	}
	
	function _rewardPunishment_getDialog(){
		$this->load->model('rewardPunishment_model');
		$this->load->config('rnd',true);
		$conf = $this->config->item('rnd');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		$where = $this->input->post('where');
		$translate = $this->input->post('translate');
		
		$this->load->view('utils/searchDialog/rewardPunishment/searchDialog', array(
			'return_fields'=>$return_fields,
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'where'=>$where,
			'limit'=>$conf['search']['limit'],
			
			'translate'=>$translate,
			'jenis_options'=>$conf['rewardPunishment']['jenis_options'],
			'data'=>$this->rewardPunishment_model->select_last_entry("", $where)
		));
	}
	
	/**
	 * 
	 * @param $callback (function) - function callback with ('kary_id', 'kary_nama') param/argument
	 */
	function _rewardPunishment_search(){
		$this->load->model('rewardPunishment_model');
		$this->load->config('rnd',true);
		$conf = $this->config->item('rnd');
		$conf1 = $conf['rewardPunishment']['jenis_options'];
		
		//ada kodenya, jadi load config dulu
		$key = $this->input->post('key');
		$keysss = array();
		$keysss[] = $key;
		if ($ss = array_search(ucwords($key), $conf1)) $keysss[] = $ss;	//key untuk jenis
		
		$limit = $this->input->post('limit');
		$offset = $this->input->post('offset') * $limit;
		$orderby = $this->input->post('orderby');
		$where = $this->input->post('where');
		$translate = $this->input->post('translate');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		
		$table_content = "";
		$row = 0;
		$data = array(
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'return_fields'=>$return_fields,
			
			'translate'=>$translate,
			'jenis_options'=>$conf1,
			'data'=>$this->rewardPunishment_model->select_last_entry($keysss, $where, $limit, $offset, $orderby),
		);
		$table_content = $this->load->view('utils/searchDialog/rewardPunishment/searchDialog_tableContent', $data,true);
		echo json_encode(array(
			'table_content'=> $table_content,
			'table_num_record'=> $key? $data['data']->num_rows() : $this->rewardPunishment_model->count_record()
		));
	}
	
	/* end of rewardPunishment search dialog *************************************************************/
	
	/********************************
	 * Pelapor search dialog
	 ********************************/
	function pelapor($func, $a=false, $b=false, $c=false, $d=false){
		$this->{"_pelapor_$func"}($a, $b, $c, $d);
	}
	
	function _pelapor_getDialog(){
		$this->load->model('pelapor_model');
		$conf = $this->config->item('rnd');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		$where = $this->input->post('where');
		$translate = $this->input->post('translate');
		
		$this->load->view('utils/searchDialog/pelapor/searchDialog', array(
			'return_fields'=>$return_fields,
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'where'=>$where,
			'limit'=>$conf['search']['limit'],
			'translate'=> $translate,
			'data'=>$this->pelapor_model->select_last_entry("", $where)
		));
	}
	
	/**
	 * 
	 * @param $callback (function) - function callback with ('kary_id', 'kary_nama') param/argument
	 */
	function _pelapor_search(){
		$this->load->model('pelapor_model');
		$conf = $this->config->item('rnd');
		
		$key = $this->input->post('key');
		$limit = $this->input->post('limit');
		$offset = $this->input->post('offset') * $limit;
		$orderby = $this->input->post('orderby');
		$where = $this->input->post('where');
		
		$return_fields = $this->input->post('return_fields');
		$submit_action = $this->input->post('submit_action');
		$cancel_action = $this->input->post('cancel_action');
		$back_action = $this->input->post('back_action');
		$translate = $this->input->post('translate');
		
		$table_content = "";
		$row = 0;
		$data = array(
			'submit_action'=>$submit_action,
			'cancel_action'=>$cancel_action,
			'back_action'=>$back_action,
			'return_fields'=>$return_fields? $return_fields : 'lapor_id,lapor_nama,lapor_nik',
			'translate'=>$translate,
			'data'=>$this->pelapor_model->select_last_entry($key, $where, $limit, $offset, $orderby),
		);
		$table_content = $this->load->view('utils/searchDialog/pelapor/searchDialog_tableContent', $data,true);
		echo json_encode(array(
			'table_content'=> $table_content,
			'table_num_record'=> $key? $data['data']->num_rows() : $this->pelapor_model->count_record()
		));
	}
	
	/* end of pelapor search dialog *************************************************************/
}
/* End of file utils/karyawan.php */
/* Location: ./system/application/controllers/utils/karyawan.php */